package com.atguigu.gulimall.search.controller;

import com.atguigu.common.to.es.SkuEsModel;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/search")
public class ElasticSaveController {

    @Autowired
    private ProductSaveService productSaveService;


    @PostMapping("/save/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels) {
        try {
            boolean res = productSaveService.productStatusUp(skuEsModels);
            if (res) {
                return R.error(3, "商品上架异常");
            }
            return R.ok(res);
        } catch (Exception e) {
            log.error("商品上架错误：{}", e);
            return R.error(3, "商品上架异常");
        }
    }

}
